﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Box.Entities;
namespace Box.Repository
{
   public class BancoRepository: MasterRepository,IBancoRepository
    {
        public List<Banco> GetAllFromBancos()
        {
            var query = from c in Context.Bancos
                        select c;
            return query.ToList();
        }

        public List<Banco> GetFromBancosByCriterio(string criterio)
        {
            var query = from c in Context.Bancos
                        select c;
            if (criterio != null && criterio != string.Empty)
            {
                query = from c in query
                        where c.NombreBanco.ToUpper().Contains(criterio.ToUpper())

                        select c;
            }
            return query.ToList();
        }

        public Banco GetFromBancosById(int id)
        {
            return Context.Bancos.Find(id);
        }

        public void AddBanco(Banco Banco)
        {
            Context.Bancos.Add(Banco);
            Context.SaveChanges();
        }

        public void UpdateBanco(Banco Banco)
        {
            Context.Entry(Banco).State = EntityState.Modified;
            Context.SaveChanges();
        }

        public void RemoveBanco(int id)
        {
            var existe = Context.Bancos.Find(id);
            if (existe != null)
            {
                Context.Bancos.Remove(existe);
                Context.SaveChanges();
            }
        }

        public bool ExisteBanco(int id)
        {
            throw new NotImplementedException();
        }
    }
}
